package org.oos.atom.entries.impl;

import static org.oos.atom.elements.Category.Type.TRUSTED;

import java.util.List;

import org.oos.atom.elements.AbstractOosEntry;
import org.oos.atom.elements.Category;
import org.oos.atom.entries.ContactEntry;

import com.google.api.client.util.Key;

public class ContactEntryImpl extends AbstractOosEntry implements ContactEntry, Cloneable {
	private static final long serialVersionUID = 6886090625627987762L;

	@Key("oos:avatar")
	private String avatar;
	
	@Key("oos:slug")
	private String slug;
	
	private Category trusted;

	@Override
	public String getAvatar() {
		return avatar;
	}
	
	@Override
	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	@Override
	public String getSlug() {
		return slug;
	}

	@Override
	public void setSlug(String slug) {
		this.slug = slug;
	}

	@Override
	public Category getTrusted() {
		if (trusted == null) {
			List<Category> cats = Category.find(super.getCategories(), TRUSTED);
			if (cats.size() > 0) {
				trusted = cats.get(0);
			}
		}
		return trusted;
	}

	@Override
	public void setTrusted(Category trusted) {
		this.categories = Category.delete(this.categories, TRUSTED);
		this.categories.add(trusted);
		this.trusted = trusted;
	}

	@Override
	public ContactEntryImpl clone() throws CloneNotSupportedException {
		return (ContactEntryImpl) super.clone();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof ContactEntry) {
			ContactEntry other = (ContactEntry) obj;
			return other.getAuthor().getSlug().equals(getAuthor().getSlug()) && other.getSlug().equals(getSlug());
		}
		return false;
	}

}
